package com.contract.spirit.ui.withdraw

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.contract.commonlib.http.status.ResultState
import com.contract.commonlib.base.BaseViewModel
import com.contract.commonlib.http.ext.request
import com.contract.spirit.bean.response.WithDrawResponse
import com.contract.spirit.config.SmsCodeConfig
import com.contract.spirit.func.net.rxApi
import com.contract.spirit.manage.CommonConfigManager

/**
 * @author: witness
 * created: 2021/9/29
 * desc:
 */
class WithDrawViewModel : BaseViewModel() {
    val withDrawConfigRes = MutableLiveData<ResultState<WithDrawResponse>>()
    val emsCodeObserve = MutableLiveData<ResultState<String>>()
    val withdrawSuccessRes = MutableLiveData<ResultState<String>>()
    var coinAddressValue = ObservableField<String>()

    var coinNumValue = ObservableField<String>()
    var emsCodeValue = ObservableField<String>()
    var cashFee= ObservableField<String>()
    var cashMinQuantity= ObservableField<String>()

    fun getWithDrawConfig() {
        request(
            { rxApi.getAppConfig() },
            withDrawConfigRes,
            withDrawConfigRes.value == null
        )
    }

    fun getEmsCode() {
        request(
            {
                rxApi.getEmsCode(
                    CommonConfigManager.userInfoResponse.phone!!,
                    SmsCodeConfig.WITHDRAW
                )
            },
            emsCodeObserve,
            isShowDialog = true,
            loadingMessage = true
        )
    }

    fun startWithDraw(type: String?, actAmount: String,  payPwd: String) {
        request(
            {
                rxApi.startWithDraw(
                    type,
                    coinAddressValue.get().toString(),
                    coinNumValue.get().toString(),
                    emsCodeValue.get().toString(),
                    actAmount, cashFee.get().toString(), payPwd
                )
            },
            withdrawSuccessRes,
            withDrawConfigRes.value == null
        )
    }
}